home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 017 / batcom.dqc / BATCOM.DOC
Encoding:
Text File  |  1984-05-17  |  25.4 KB  |  783 lines

  1.  
  2.  
  3.  
  4.                          BAT.COM - FUNCTIONS
  5.                          -------------------
  6.  
  7.                                 
  8. QUICK REFERENCE:
  9. ---------------
  10.  
  11.  
  12. Batch file commands [operands]                  Batch file statement:
  13.  
  14.  
  15.   BEEP      [stmt]                                BAT -[lbl] [cmd] | [cmd]
  16.   BEGSTACK...[text] [\hex] [;]... END
  17.   BEGTYPE ...[text] [\hex] [;]... END          Control Functions:
  18.   CALL     -[lbl]                                 STACK.ON
  19.   CLS       [stmt]                                STACK.OFF
  20.   EXIT      [stmt] -stopbatch,ret to DOS          STACK.PURGE
  21.   GOTO     -[lbl]                                 TRACE.ON
  22.   IF        [token] < = > <> [token] [stmt]       TRACE.OFF
  23.   INKEY     [text] [var] 
  24.   READ      [text] [vars]                      Variables:
  25.   READSCRN  [vars]                               %0 to %9 - DOS Vars
  26.   RETURN                                         %A to %O - Global Vars
  27.   SKIP      [numoflines]                         %Q - Stack status(S or K)
  28.   STATEOF   [filename].or.[var]                  %R - Return Code [0:4FE]
  29.   STACK  ...[tokens] [;]...                      %S - Space Literal
  30.   TYPE   ...[tokens] [;]...                      %V - Default Drive
  31.   [var]  =  [token] + - * / # $ [token]          %% - "%" Literal
  32.   
  33.   | delimits multiple commands on a line
  34.   
  35.   * [comment]
  36.  
  37.  
  38. NOTES:
  39.  
  40.  1) Standard DOS commands can be intermixed freely with BAT commands.
  41.  2) Like basic, things at the top are quick for goto's / loops to find.
  42.  3) A skip is faster than a goto, but can only move down the bat file.
  43.  4) Up to 15 chars are allowed for labels, contents of vars, and literals
  44.  5) 10 variables are provided to be passed to/from DOS. They're %0 to %9.
  45.  6) 15 variables are provided for user use only. They're %A to %O.
  46.  7) The variable %R is a return code that any routine can set at [0:04FE]
  47.  8) 'BEGTYPE' & 'BEGSTACK' do not do variable substitution.
  48.  9) BEGTYPE  command can have screen attributes via a '\hex' format.
  49. 10) BEGSTACK command can have timing attributes via a '\hex' format.
  50. 11) Spaces are needed to delimit operators.
  51. 12) Non-spaces will concatenate variables and literals.
  52. 13) STATEOF sets %R (return code) as the state of existence of a file.
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.                       DETAILED DESCRIPTION
  60.                       --------------------
  61.  
  62.  
  63.  
  64.  
  65.  
  66. TYPE command: Prints text and contents of variables on display.
  67. ------------
  68.  
  69.  example:
  70.  
  71.     BAT TYPE HELLO THERE
  72.  
  73. You can also put DOS variables into this command to display their
  74. contents.  For example, if the "TRIAL.BAT" file contained the line:
  75.  
  76.     BAT TYPE HELLO THERE %1 %2
  77.  
  78. Then when we start the BAT program from DOS, we might enter:
  79.  
  80.     TRIAL COMPUTER USER          * COMPUTER ==> %1, USER ==> %2
  81.                                      
  82. DOS will automatically store the words after the program name into its
  83. variables.  Therefore, in the TYPE command, we will see contents of these
  84. variables on the screen.  The resulting message would be:
  85.  
  86.     HELLO THERE COMPUTER USER
  87.  
  88. If the %4 variable contains the word DAY, the command to display
  89. the words FUN DAY on the display is: BAT TYPE FUN %4.
  90.   
  91.  
  92.  
  93.  
  94. BEGTYPE command: a second method of putting text onto the display.
  95. ---------------
  96.  
  97. Although it will not display the contents of variables, it is very
  98. useful for displaying large blocks of text, such as menus.
  99.  
  100.     For example, if the "TRIAL.BAT" file contains:
  101.  
  102.     BAT BEGTYPE
  103.     This is a large block of text. It is useful for menus. Note
  104.     that Upper/Lower case characters are displayed intact here.
  105.     The block is always ended with "END" in the first column
  106.     after the text finishes.
  107.     END
  108.  
  109.  
  110. When executed, the "TRIAL.BAT" program will display:
  111.  
  112.     This is a large block of text. It is useful for menus. Note
  113.     that Upper/Lower case characters are displayed intact here.
  114.  
  115.  
  116.  
  117. The begtype command can also highlight text by using the form:
  118.  
  119.             [\hex]          
  120.  
  121. For example, if the text block contained \0f within the text, the result
  122. would be High Intensity Text.
  123.  
  124. By choosing different values, the screen attributes can be controlled to
  125. create inverted video, blinking, underlined, and very colorful text.
  126.  
  127. BEGTYPE display control example:
  128.  
  129.     bat begtype
  130.  
  131.         \04Normal                            Red on Black  \07
  132.         \0fHigh Intensity                    High Intensity\07
  133.         \21Underlined                        Blue on Green \07
  134.         \85Flashing Normal                   Flashing Magenta on Black\07
  135.  
  136.                 And \0fmany\07 other combinations!
  137.  
  138.  
  139. \1b[33;44m Users of DOS 2.0 ANSI.SYS can also control the display. \1b[0m
  140.  
  141.         end
  142.  
  143.  
  144.  
  145. bat     begtype
  146. <\0FS\07>ystem    <\0FD\07>emo    <\0FH\07>elp
  147. end
  148.  
  149. \0F causes a change to high intensity for the characters that follow
  150. within a begtype command,  while \07 restores all following to normal
  151. intensity.
  152.  
  153.  
  154.  
  155.  
  156. CLS command: used to clear the display before printing data.
  157. -----------
  158.  
  159.     "BAT CLS  BEGTYPE" is useful for printing menus and text to the screen.
  160.  
  161.  
  162. READ command: reads 1 input line, typed from the keyboard or the stack.
  163. ------------
  164.  
  165. When the command word READ is seen in the batch file, an input line is
  166. accepted from the user.  All function keys are assigned to the normal DOS
  167. edit functions.  When ENTER is pressed, the input line is assigned to *DOS*
  168. variables.
  169.  
  170. Each word will be assigned in order to the variables indicated after the
  171. READ command.  When there are no more variables after the READ command to
  172. assign, the remainder of the response is thrown away.  If there are more
  173. variables to be assigned after the READ command than there are words from
  174. the user, these variables will be cleared out to a empty state.  For
  175. example:
  176.  
  177.     BAT READ Please enter your name ==> %1 %2
  178.  
  179. This would prompt the user and wait for him to enter two words.  These
  180. words will be saved in the %1 and %2 variables.
  181.  
  182. Note that there does not have to be any variables indicated after the
  183. command READ.  In this case, BAT would wait for the enter key, throw away
  184. any response, then continue to process the next batch file command.
  185.  
  186.  
  187. INKEY command: gets a single keystroke from the keyboard or stack.
  188. -------------
  189.  
  190. This command will wait for the user to enter a single key on the keyboard
  191. and return its value in the optional variable.    This key can be not only
  192. letters, but all function keys, control keys, etc.  For example:
  193.  
  194.     BAT INKEY Press any key to continue... %0
  195.  
  196. When the user presses a single key, that key is saved into the variable %0.
  197.  
  198. If the key that is pressed is in the range of "!" to "z" (decimal 33 to
  199. 122) then the key is saved to the optional variable.
  200.  
  201.      ** If you wish this key to be echoed to the display,
  202.         you must specifically use the TYPE command.
  203.  
  204. If the key is NOT in the above range, then the key will be converted to
  205. the form "KEYxxx" where xxx is the hex value of the key.  Extended key
  206. codes will be in the range KEY100 to KEY1FF and nonextended key codes will
  207. be in the range KEY000 to KEY0FF.  Refer to Appendix G of the Basic manual
  208. for a complete description of the various assignments of key codes.
  209.  
  210. The character does not have to be assigned to a variable.  If the
  211. variable name is not present following the command INKEY, the system will
  212. wait for any key to be pressed from the user, and then continue processing.
  213.  
  214.  
  215.  
  216.  
  217. PROGRAM  CONTROL:  GOTO, CALL, RETURN, and IF commands
  218. ------------------------------------------------------
  219.  
  220.  
  221. GOTO command:
  222. ------------
  223.  
  224.     BAT GOTO -LABEL
  225.  
  226. If this line is put into a ".BAT" file, then it will stop execution at
  227. this line and resume at the line within the file which contains:
  228.  
  229.     BAT -LABEL
  230.  
  231. This is a unconditional branch.  If the label is not present within the
  232. file, an error will result.  Note the minus (-) sign before the label
  233. name.  Labels must be preceded with a minus sign.
  234.  
  235.  
  236. CALL command:
  237. ------------
  238.  
  239. The line where the CALL command is encountered is saved, then a branch
  240. to a label is done, as with the GOTO command. However, only THREE lines can
  241. be saved away, at a time, with this command.
  242.  
  243. When a RETURN command is found, the last line that was saved is restored.
  244. Execution resumes at the line following the original CALL command.
  245.  
  246.   For example, if a program contains:
  247.  
  248.     BAT    TYPE One
  249.     BAT    CALL -LABEL
  250.     BAT    CALL -LABEL
  251.     BAT    TYPE Four
  252.     BAT    EXIT
  253.     BAT -LABEL
  254.     BAT    TYPE Two
  255.     BAT    TYPE Three
  256.     BAT    \07RETURN\07
  257.  
  258.   You will see on the display:
  259.     ONE
  260.     TWO
  261.     THREE
  262.     TWO
  263.     THREE
  264.     FOUR
  265.  
  266.  
  267.  
  268.  
  269. IF command:
  270. ----------
  271.  
  272.   The general form of this command is:
  273.  
  274.     BAT IF _word  _condition   _word   _operation
  275.  
  276.  
  277. Each _word can be a fixed string of letters, or a variable, or a
  278. combination of each.
  279.  
  280.    _condition can be:
  281.  
  282.     <    less than
  283.     =    equal to
  284.     >    greater than
  285.     <>    not equal to
  286.  
  287. _operation can be any of the Extended Batch Language commands.
  288.  
  289. For example, all of the following IF statements will compare correctly
  290. and execute their corresponding TYPE command.  The first two statements
  291. will initialize variables used in the IF commands.
  292.  
  293.     BAT %1 = ABC
  294.     BAT %2 =
  295.  
  296.     BAT IF ABC = %1  TYPE The variable contains ABC.
  297.     BAT IF %1 = abc  TYPE This also matches.
  298.     BAT IF 0 <> 00     TYPE These are different lengths.
  299.     BAT IF 0 < 00     TYPE 0 has a smaller length.
  300.     BAT IF 456 > 123 TYPE Numerically, 456 is bigger.
  301.     BAT IF 456 < %1  TYPE ASCII value of 456 is smaller.
  302.     BAT IF AABCD = A%1D TYPE Token substitutions are made.
  303.     BAT IF %2 <> %1  TYPE Variables are different lengths.
  304.     BAT IF .%2 = .     TYPE This matches if var is empty.
  305.     BAT IF BOX = BOX IF DOG <> CAT TYPE Did multi-if compare.
  306.  
  307.  
  308.  
  309.  
  310. Another,
  311.  
  312. bat    inkey %k
  313. bat    if %k = KEY003         goto -opt0        |* Break key
  314. bat    if %k = KEY01B %L = 0       | return        |* ESC  key
  315. bat    if %k = KEY147 %L = 0       | return        |* Home key
  316. bat    if %k = KEY149 %L = %L - 1 | cls | return  |* PgUp key
  317. bat    if %k = KEY151 %L = %L + 1 | cls | return  |* PgDn key
  318. bat    if .%a <> . skip 8                       |* end of string ?
  319. bat    read Press the ─┘ key to continue to next section.....
  320. bat    return
  321. bat    %b = %a $ 1 1                    |* get 1st letter
  322. bat    %a = %a $ 2                    |* remove it from string
  323. bat    inkey %i                    |* get a key.
  324. bat    if %i = KEY020 type %b; | goto -tryit.loop
  325. bat    if %i = %b type %i; | goto -tryit.loop
  326. bat    beep goto -tryit.try
  327.  
  328.  
  329.  
  330. more if's, etc....
  331.  
  332. bat    read Enter the number of your selection. > %A
  333. bat    if / = /%a    %a = 1
  334. bat    if %a < 13 if %a > 1/ cls goto -opt%a
  335. bat    if %a < :  if %a >  / cls goto -opt%a
  336. bat    beep begtype
  337. I DON'T KNOW THAT OPTION!
  338. Just enter a number 0 to 12 and press the ─┘ key.
  339. end
  340.  
  341.  
  342.  
  343. bat     begtype
  344. <\0FS\07>ystem    <\0FD\07>emo    <\0FH\07>elp    *prompt for next test
  345. end
  346.  
  347. bat    -exiting inkey %a                               *read kybd
  348. bat        if %a = S    exit                   *stop batch,ret DOS
  349. bat        if %a = H    goto -line0            *jmp to start
  350. bat        if %a = D    stack BATDEMO | exit   *put a command on
  351. bat                                                    *the stack,& exit
  352. bat        beep goto -exiting                     *if's failed
  353.  
  354.  
  355.  
  356.  
  357.  
  358.  
  359. KEYBOARD STACK....
  360.               
  361.  
  362.   There is a method within the BAT language for answering questions from
  363. programs without operator intervention.  This is done by a "keyboard
  364. stack".  By entering data into the stack, you will essentially be entering
  365. data through your keyboard when any program requests it.  In this way, a
  366. batch file can now answer questions programs may have by 'typing' them for
  367. the user.
  368.  
  369.   The keyboard stack operates in a "first-in first-out" basis.  That is,
  370. the first line of text put into the stack will be the first seen by the
  371. program when it reads the keyboard.  The second line entered will be the
  372. second seen by the program, and so on.    As long as there is text remaining
  373. on the stack, ALL requests for data from the keyboard will actually come
  374. from the stack.  Once the stack has been emptied by the program, data will
  375. then come from the keyboard as usual.
  376.  
  377.  
  378. STACK command:
  379. -------------
  380.  
  381. It will "push" data into the keyboard stack area.  When any program is ready
  382. to accept information from the keyboard, the parameters after the STACK
  383. command will be used as input.
  384.  
  385.  
  386. For example:
  387.  
  388.     BAT * This program will issue remarks to DOS.
  389.     BAT %1 = HELLO
  390.     BAT STACK REM THIS IS A REMARK FOR DOS
  391.     BAT STACK REM VARIABLE %%1 = %1
  392.  
  393.  
  394. When executed, the following will appear on the screen:
  395.  
  396.     A>REM THIS IS A REMARK FOR DOS
  397.  
  398.     A>REM VARIABLE %1 = HELLO
  399.  
  400.  
  401.  
  402.  
  403. BEGSTACK command: used to dump large amounts of data to the stack area. 
  404. -----------------
  405.  
  406.  
  407. Although no parameter substitution is performed, there are several
  408. advantages to its use.
  409.  
  410. 1) If a line ends with the ";" (semicolon) character, a carriage
  411.    return will NOT be stacked. 
  412.  
  413. 2) If "\HEX" is used (HEX is a number from 01 to FE) then this exact
  414.    keyboard value will be stacked.  This is useful for stacking special
  415.    control characters and symbols.
  416.  
  417. 3) If "\00\HEX" is used, an EXTENDED key code will be stacked.
  418.    This is useful for stacking FUNCTION keys and the like. 
  419.    Refer to the Basic manual in Appendix G under "Extended Codes".
  420.  
  421. 4) If \FF\HEX is used, the stack will delay the keyboard characters from
  422.    appearing to the program for HEX number of CPU "ticks". 
  423.    There are about 12 hex (18 decimal) ticks per second in the CPU. 
  424.  
  425. In all cases, the word HEX above represents a two digit
  426. hexadecimal number. Finally, \\ can be used to stack a single backslash.
  427.  
  428.  
  429. An example of a BEGSTACK command::
  430.  
  431.     BAT BEGSTACK
  432.  
  433.     \09                           *  Will stack the tab key.
  434.     This text will be stacked ;
  435.         on one line!
  436.     \00\3B                        * Will stack an F1 key.
  437.     \\                            * Is seen as one backslash.
  438.     \FF\24                        * Will pause two seconds.
  439.  
  440.     end
  441.  
  442.  
  443. another...
  444.  
  445.     bat begstack
  446. This text is actually being typed for you from the keyboard stack.
  447. All keys, including control keys and function keys can come from the stack.
  448. Keystrokes can \ff\10even \ff\10have \ff\10delayed \ff\10typing.
  449. \1a
  450.         end
  451.  
  452.  
  453.  
  454. rem ... Below is the DOS command that will read the keyboard stack.
  455. copy con: nul:
  456. bat *returning from DOS command*
  457.  
  458.  
  459.  
  460. Hint: Some programs remove keystrokes before accepting a critical key. In
  461. some cases this can be avoided by using \FF\01 in the BEGSTACK command.
  462.  
  463.  
  464.  
  465. There are also three control commands which are associated with the stack:
  466.  
  467. STACK.OFF     - Redirects data to come directly from
  468.         the physical keyboard. Does not remove
  469.         any data in the stack.
  470.  
  471. STACK.ON      - Directs data to come from the stack.
  472.         This is the default.
  473.  
  474. STACK.PURGE   - Removes any data from the stack and
  475.         keyboard buffers which are pending.
  476.  
  477. The size of the keyboard stack defaults to 512 bytes.  This value can be
  478. changed by making the FIRST STATEMENT which is executed by the Extended
  479. Batch Language program be of the form:    "BAT * size". 
  480.  
  481. Size is the decimal number of bytes to reserve for the stack.  This must
  482. be executed, for instance, when a system reset is performed because once
  483. this area is installed, the size is never altered until another system reset.
  484.  
  485.  
  486.  
  487.  
  488.  
  489.  
  490. READSCRN command:
  491. ----------------
  492. A line of text is read from the display screen into variables.  
  493. Having the ability to read text from the display can be useful 
  494. for determining the result of another program, or making a query
  495. for some system status which would not normally be available within
  496. a batch file.
  497.  
  498. For example, by reading a DIRECTORY from the screen,  a series of
  499. files can be submitted to the macro assembler.
  500. Once the assembly is completed, the status can be read from the
  501. screen to determine if there were errors which would stop the link step.
  502.  
  503. Virtually any message which a program can generate can be used as 
  504. feedback to a batch file by using READSCRN.
  505.  
  506. Its operation is very much like the READ command except for the fact that
  507. the information which is being read is coming from the display screen and
  508. not the keyboard.  Like the READ command, the text from the screen is
  509. tokenized (separated at word boundaries and assigned to variables).  The
  510. return code %R will be reflect the line number on the display that was
  511. read.  This number will be in the range of 1 to 25 for the top to bottom
  512. lines respectively.
  513.  
  514. Once a line is read, this command will be set to read the PREVIOUS line.
  515.  
  516. Repeated "readscrn" commands will read *> UP <* the display!!!
  517.  
  518.  
  519.  
  520. A READSCRN example:
  521.  
  522.     BAT CLS
  523.     BAT TYPE HELLO THERE
  524.     BAT READSCRN %A %B %C
  525.  
  526. After execution:
  527.     %A contains HELLO
  528.     %B contains THERE
  529.     %C contains nothing, it is empty.
  530.     %R (return code) contains 1, the line number that was read.
  531.  
  532. From our menu, we have started the IBM Macro Assembler program.  We know
  533. that when this program ends, it will display a number representing the
  534. number of errors that were found.  We want to make sure that this number is
  535. zero before continuing to the LINK program.  If we save this number in the
  536. variable %A, what is the command to read the assembler result from
  537. the display?
  538.  
  539.          BAT  READSCRN   %A
  540.  
  541.  
  542.  
  543.  
  544.  
  545.  
  546. STATEOF command: Will search all disk drives for the existance of a file.
  547. ---------------
  548.  
  549. The name after the word STATEOF can be a specific name, general name with
  550. wildcard characters (e.g. *.EXE), or it can be a name with a specific drive
  551. and extension, e.g. A:PE.EXE). In the last case, only drive A: will be
  552. searched instead of all available drives. Note also that a variable can be
  553. used instead of a file name. In this version of BAT, only files in the
  554. current directory (no paths) can be found.
  555.  
  556. The return code variable %R is used to indicate the result of the search
  557. for STATEOF. The results are:
  558.  
  559.     0 - File found on default drive.
  560.     1 - File not found.
  561.     9 - Invalid file name specified.
  562.     A to D - Same as return code 0 but instead of being found on the
  563.         default drive, it was found on drive A, B, C, or D.
  564.  
  565. User programs may also set the return code in order to control the
  566. execution of the BAT batch file program, but this is most commonly done
  567. when using the command STATEOF to search for a file.
  568.  
  569. If a file exists, we could direct a program to use it, even if it wasn't
  570. on the specific diskette drive that the operator was expecting.
  571.  
  572. If the file was not there, we could have printed out an error message to the
  573. operator, or we could have run an alternate program in order to create the
  574. missing file.
  575.  
  576.  
  577.  
  578. STATEOF command example:
  579.  
  580.     bat type Enter a filename for me to search for:
  581.     bat read %9
  582.     bat type scanning for file: %9 . . .
  583.     bat stateof %9 * this will search and set the return code up (%R)
  584.     bat if %r <> 0 skip 2
  585.     bat    type the file does exist - exactly as typed.
  586.     bat    skip 7
  587.     bat if %r <> 1 skip 2
  588.     bat    type the file does not exist on any drive.
  589.     bat    skip 5
  590.     bat if %r <> 9 skip 2
  591.     bat    type the file name given is invalid.
  592.     bat    skip 2
  593.     bat type the file does exist - but was found on the %r drive.
  594.     bat type to properly find this file, the complete filename would be %9
  595.  
  596.  
  597.  
  598.  
  599. ASSIGNMENTS:
  600. -----------
  601.  
  602.   If the first character in the command is a '%' (Percent sign), then it is
  603. considered to be an assignment statement.  The first variable cannot be any
  604. predefined variable (such as %R or %), but may be any of the other
  605. variables %0 to %9 and %A to %O.  If a DOS command is later executed and
  606. uses one of the variables %0 to %9, it will be properly replaced with the
  607. contents of that variable.
  608.  
  609. The first assignment token, the operator, and the final tokens are optional.
  610.  
  611. The assignment statement must appear in one of the following forms:
  612.  
  613. [var] =                               * create empty variable
  614. [var] = [string]              * simple assignment
  615. [var] = [number] + [number]          * addition
  616. [var] = [number] - [number]          * subtraction
  617. [var] = [number] * [number]          * multiplication
  618. [var] = [number] / [number]          * division
  619. [var] = [string] #              * string length
  620. [var] = [string] $ [index] [length]   * create substring (like MID$ in BASIC)
  621.  
  622.  
  623. where:
  624.  
  625. [var]    is a DOS variable or global user variable %0 to %9 
  626.          and %A to %O.  It may not be a predefined variable.
  627.  
  628. [string] is any valid token.  Letters, numbers, any variable, or any
  629.          combination.
  630.         
  631.          123, ABC, and 987%J4SF are all valid strings.
  632.  
  633. [number] is any token with a numeric result in the range of 0 to
  634.          65535.    For example (if %A contains 34) the three numbers
  635.          98, %A, and 12%A5 (equivalent to 12345) would all be valid
  636.          numbers.  Note that numbers are always positive and should 
  637.          never contain a sign ( + or - ) character.
  638.  
  639. [index] Same restrictions as [number] above except that an [index] in
  640.         the range 17 to 65535 is meaningless and is equivalent to the
  641.         number 16.
  642.  
  643. [length]Same restrictions as [number] above except that a
  644.         [length] in the range 16 to 65535 is meaningless and 
  645.         is equivalent to the number 15.  Note that [length] is
  646.         optional and has a default value of 15.
  647.  
  648.  
  649.  
  650.  
  651.  
  652. ADDITIONAL INFO:
  653.  
  654. There are additional variables %A thru %O (oh) which are called "global
  655. user variables".  These variables are used exactly like the variables
  656. supplied by DOS (%0 to %9) with TWO EXCEPTIONS. 
  657.  
  658. 1) The contents of these variables are maintained between execution of
  659.    batch files for as long as the system is powered on.  This "global"
  660.    feature is useful for keeping indicators BETWEEN "sessions" of the user.
  661.  
  662. 2) Because DOS does not know about these variables, they CANNOT BE USED 
  663.    AS VARIABLES WITHIN ANY DOS COMMAND.  So "COPY %1 %2" is valid,
  664.    "COPY %A %B" is not.  If you wish to use them within DOS commands, 
  665.    they must first be copied via a statement like "BAT %1 = %A".
  666.  
  667.  
  668.  
  669. PREDEFINED VARIABLES...
  670.  
  671. A return code is available at memory address [0000:04FE].  If set by a
  672. program, BAT can read this byte value with the variable %R.  The string
  673. stored into this variable is in hex with leading zeros truncated.
  674.  
  675. The current default drive is stored into the %V variable.  It is a single
  676. character.
  677.  
  678. The status of the stack is stored into the %Q variable.  It is a "K" if
  679. the READ command will be reading from the keyboard, and a "S" if it will be
  680. reading from the stack area.
  681.  
  682. There are two character literals.  %S represents a space literal and %%
  683. represents a percent sign.  Either of these special variables can be stored
  684. into other variables, or used for testing special cases.
  685.  
  686.  
  687. OTHER CONTROLS...
  688.  
  689. If a you wish to put more than one command on a line, the vertical bar
  690. "|" is useful.  When used with an IF command and the test for the IF
  691. conditions fail, the entire rest of the line will be ignored.  Multiple
  692. commands within a BAT statement is very useful when combined with the IF
  693. command.  For example:
  694.  
  695.     BAT IF %A = abc TYPE this | CALL -that | GOTO -other
  696.  
  697.   If a comment is needed within a BAT program, the "*" (star) character is
  698. useful.  When used after the word BAT, all characters which follow will be
  699. ignored.  For example:
  700.  
  701.     BAT * This is a comment to the programmer.
  702.  
  703.  
  704.  
  705.  
  706.  
  707.  
  708. MORE.....
  709.  
  710. A BAT program can create loops and count events. With this you can
  711. sequence through file numbers, or create loops to do retrys in case of
  712. errors. In addition, BAT programs can do simple arithmetic and string
  713. manipulation.
  714.  
  715. EXAMPLE:
  716.  
  717. bat * number guessing demo *
  718. bat %7 = 30
  719. bat %6 = 5
  720.    bat cls type I am thinking of a two digit number, can you guess it?
  721.    bat -c.loop read %5
  722.    bat if %5 = %7 skip 7
  723.    bat %6 = %6 - 1
  724.    bat if %6 <> 0 skip 2
  725.        bat type boo hisss! the number was %7!
  726.        bat skip 4
  727.    bat if %5 > %7 type try a little lower. you only get %6 more tries.
  728.    bat if %5 < %7 type try a higher number. you get %6 more tries.
  729.    bat goto -c.loop
  730.    bat type great! i was afraid you weren't going to get it!
  731.  
  732.  
  733. In this example, a directory is displayed by using a DOS command within 
  734. a batch file. ANY DOS COMMAND can be mixed freely within lines of the 
  735. BAT program.
  736.  
  737.  
  738.    bat cls
  739.    bat * display a directory
  740.    bat type Enter a file specification or just enter key for all:
  741.    bat read %1
  742.    bat if .%1 = . %1 = *.*
  743.    bat -dirques type Would you like a (S)tandard or (W)ide directory?
  744.    bat inkey %2 | %m = %2 # | if %m = 1 type %2
  745.    bat * Notice you can chain togeather if's, like . . .
  746.    bat if %2 <> s if %2 <> w goto -dirques   * EQUIV OF AN `AND' FUNCTION
  747.    bat %3 =
  748.    bat if %2 = w %3 = /w
  749.    bat cls
  750.    DIR %1 %3  (notice that two parms are passed to dos here. %%1 and %%3)
  751.  
  752. By passing parameters to/from DOS, you can have complete control
  753. of how a program operates.
  754.  
  755.  
  756.  
  757.  
  758.  
  759.  
  760. DEBUGGING
  761. ---------
  762.  
  763. TRACE.ON command:
  764. ----------------
  765.  
  766.        Enables a trace flag which causes each line
  767.        in the BAT program to be printed as it is executed.
  768.        Three '+' (plus) symbols will precede the BAT statement
  769.        that is printed out.
  770.  
  771.   A trace can be active during DOS commands within the BAT program.  In
  772. addition, trace can be enabled/disabled at any time, even in immediate
  773. mode.  Once enabled, it will remain in effect until the TRACE.OFF command
  774. is executed.  Errors, execution of other BAT language files, and even
  775. executing DOS commands will not change the trace mode.
  776.  
  777. TRACE.OFF command: Disables trace
  778. -----------------
  779.  
  780. s type I am thinking of a two digit number, can you guess it?
  781.    bat -c.loop read %5
  782.    bat if %5 = %7 skip 7
  783.    bat %6 = %6